package com.MedDroid.activity;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.MedDroid.MainApp;
import com.MedDroid.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import com.MedDroid.task.LoadGraphTask;
import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.GraphViewSeries;
import com.jjoe64.graphview.LineGraphView;

/**
 * Created with IntelliJ IDEA.
 * User: Matt
 * Date: 02/12/13
 * Time: 10:44 PM
 * To change this template use File | Settings | File Templates.
 */
public class GraphActivity extends Activity
{
	public int[] xaxis = new int[10];//load xaxis data here
	public int[] yaxis = new int[10];//load yaxis data here
	Button btnAddData;
	public int LoadedUser;

	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.graph_page);

		Bundle extras = getIntent().getExtras();
		if (extras != null)
		{
			LoadedUser = extras.getInt("UserID");
		}

		btnAddData = (Button) findViewById(R.id.btnAddData);
		btnAddData.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View view)
			{
				Intent intent = new Intent(GraphActivity.this, AddRecordActivity.class);
				startActivity(intent);
			}
		});
	}

	@Override
	public void onResume()
	{
		super.onResume();
		new LoadGraphTask(((MainApp)getApplication()).getDatabase(), GraphActivity.this).execute(LoadedUser);
	}

	public void drawGraph()
	{
		GraphView.GraphViewData[] data = new GraphView.GraphViewData[10];
		for (int i=0; i<10; i++) {
			data[i] = new GraphView.GraphViewData(xaxis[i], yaxis[i]);
		}
		GraphView graphView = new LineGraphView(
				this
				, "Weight vs Time"
		);

		graphView.addSeries(new GraphViewSeries(data));

		LinearLayout layout = (LinearLayout) findViewById(R.id.LinearGraph);
		layout.addView(graphView);
	}
}